import request from '@/config/axios'

// 列表查询时，接口返回的数据
export interface CheckoutConfigVO {
  id: string
  skuId: string
  agentBonus: string
  inviteBonus: string
  saleBonus: string
  fixedBonus: string
}

export type CheckoutConfigUpdateDTO = Pick<CheckoutConfigVO, 'id'> &
  Partial<
    Pick<CheckoutConfigVO, 'skuId' | 'agentBonus' | 'inviteBonus' | 'saleBonus' | 'fixedBonus'>
  >

export type CheckoutConfigCreateDTO = Pick<
  CheckoutConfigVO,
  'skuId' | 'agentBonus' | 'inviteBonus' | 'saleBonus' | 'fixedBonus'
>

export const baseURL = '/train/checkout-config'

export const get = (skuId: string) =>
  request.get({ url: `${baseURL}/get-by-sku-id`, params: { skuId } })

export const update = (data: CheckoutConfigUpdateDTO) =>
  request.post({ url: `${baseURL}/create-or-update`, data })

export const create = (data: CheckoutConfigCreateDTO) =>
  request.post({ url: `${baseURL}/create-or-update`, data })
